package com.scedu.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

//登录控制器
@Controller
public class LoginController {
    @RequestMapping("/login")
    public String login(@RequestParam("Username") String Username,
                        @RequestParam("Password")String Password,
                        Model model,
                        HttpSession httpSession){
        //具体业务，判断登录
        if(!StringUtils.isEmpty(Username)&&"123456".equals(Password))
        {
            //登录成功
            httpSession.setAttribute("username",Username);
            return "dashboard";
        }else{
            //告诉用户登录失败
            model.addAttribute("msg","用户名或者密码错误！");
            return "index";
        }

    }
    //注销
    @RequestMapping("/signout")
    public String signout(HttpSession httpSession){
        System.out.println("注销");
        httpSession.removeAttribute("username");
        return "index";
    }
}
